package day07.ThreadDemo;

/*
 * Author: JacksonCoder
 * FileName: CountDownLatchDemo
 * Version: 1.0.0
 * Date: 2025/4/14
 */

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(3);

        new Thread(() -> {
            System.out.println("Thread 1 done");
            latch.countDown();
        }).start();

        new Thread(() -> {
            System.out.println("Thread 2 done");
            latch.countDown();
        }).start();

        new Thread(() -> {
            System.out.println("Thread 3 done");
            latch.countDown();
        }).start();

        latch.await(); // 主线程阻塞直到 count 为 0
        System.out.println("Main thread continues");
    }
}
